package com.example.jwt.controller;

import com.example.jwt.annotation.LoginUser;
import com.example.jwt.annotation.MyAuthority;
import com.example.jwt.entity.TokenUser;
import com.example.jwt.service.JwtRoleService;

import com.example.jwt.utils.MyJwtUtil;
import com.example.jwt.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;



/**
 * @author: mtl
 * @Date: 2022/1/17 10:33
 * @Description:
 */
@Slf4j
@RestController
@RequestMapping("/user")
public class LoginController {

    @Autowired
    private JwtRoleService jwtRoleService;


    @RequestMapping("/login")
    public R login(String username,String password){
        String token = MyJwtUtil.getJwtToken(jwtRoleService.isUserInfo(username, password));
        return R.ok().put("token",token);
    }




    @RequestMapping("info")
    public R list(@LoginUser TokenUser tokenUser,String token){
        return R.ok(tokenUser);
    }

}
